package com.situ.mymall.controller;

import com.github.pagehelper.PageInfo;
import com.situ.mymall.annotation.MyLog;
import com.situ.mymall.pojo.entity.Cart;
import com.situ.mymall.pojo.query.CartQuery;
import com.situ.mymall.service.ICartService;
import com.situ.mymall.util.PageResult;
import com.situ.mymall.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired
    private ICartService cartService;

    @RequestMapping("/list")
    public PageResult list(CartQuery cartQuery){
        return cartService.list(cartQuery);
    }

    @RequestMapping("/selectById")
    public Result selectById(Integer id){
        Cart cart = cartService.selectById(id);
        return Result.ok(cart);
    }


    @RequestMapping("/add")
    public Result add(Cart cart){
        cartService.add(cart);
        return Result.ok("添加成功");
    }

    @RequestMapping("/deleteById")
    public Result deleteById(Integer id){
        cartService.deleteById(id);
        return Result.ok("删除成功");
    }

    @RequestMapping("/deleteAll")
    public Result deleteAll(Integer[] ids){
        cartService.deleteAll(ids);
        return Result.ok("删除成功");
    }

    @RequestMapping("/update")
    public Result update(Cart cart){
        cartService.update(cart);
        return Result.ok("更新成功");
    }

    @RequestMapping("/updateStatus")
    public Result updateStatus(Cart cart){
        cartService.updateStatus(cart);
        return Result.ok("更新成功");
    }
}
